package org.sgsm.dungeon.generator;

import java.io.File;
import java.io.IOException;

import java.util.ArrayList;
import java.util.List;

import org.sgsm.dungeon.generator.generator.CommandGenerator;
import org.sgsm.dungeon.generator.generator.ControlGenerator;
import org.sgsm.dungeon.generator.generator.EventGenerator;
import org.sgsm.dungeon.generator.generator.RemotingServiceImpl;
import org.sgsm.dungeon.generator.generator.ServiceDelegateGenerator;
import org.sgsm.dungeon.generator.generator.ServiceImplGenerator;

import org.jdom.JDOMException;

public class ClassMain
{
  public ClassMain()
  {
  }

  public static void main(String[] args) throws JDOMException, IOException
  {
    String pathIn = "E:\\TEST\\myProjet\\Service\\service";
    String pathOut = "E:\\TEST\\dungeon\\";
    List<String> listFile = listerRepertoire(pathIn);
    List<ServiceType> listService = new ArrayList<ServiceType>();
    for (String file: listFile)
    {
      Passeur.getInstance().setPathBase(pathOut + "dg_serviceUI\\src\\main\\as\\");
      ServiceType service = ServiceXmlReader.readServiceXml(pathIn, file);
      ControlGenerator service3 = new ControlGenerator();
      service3.generate(service);
      CommandGenerator serviced = new CommandGenerator();
      serviced.generate(service);
      EventGenerator servicea = new EventGenerator();
      servicea.generate(service);
      ServiceDelegateGenerator serviceg = new ServiceDelegateGenerator();
      serviceg.generate(service);
      listService.add(service);
      if (service.isCrud())
      {
        Passeur.getInstance().setPathBase(pathOut + "dg_service\\src\\main\\java\\");
        ServiceImplGenerator serviceImpl = new ServiceImplGenerator();
        serviceImpl.generate(service);
      }
    }
    Passeur.getInstance().setPathBase(pathOut + "dg_service\\");
    RemotingServiceImpl serviceg = new RemotingServiceImpl();
    serviceg.generate(listService);
  }

  public static List<String> listerRepertoire(String pPath)
  {
    List<String> result = new ArrayList<String>();
    String[] listefichiers; //
    File repertoire = new File(pPath);
    listefichiers = repertoire.list();
    for (String file: repertoire.list())
    {
      result.add(file);
    }
    return result;
  }
}
